﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using StudioLib;
namespace StuCat
{
    public partial class RoomBox : UserControl
    {
        public string Caption { get { return groupBox1.Text; } set { groupBox1.Text = value; } }
        Room room { get; set; }
        
        List<Equipment> guitars = new List<Equipment>();
        List<Equipment> basses = new List<Equipment>();
        List<Equipment> other = new List<Equipment>();

        enum InstrSelector
        {
            Guitar,
            Bass,
            Other
        }

        public RoomBox()
        {
            InitializeComponent();

            room = new Room();

          
            room.Name= "New room";

            
            LoadRoom(room);

        }

        public void LoadRoom(Room room)
        {
            groupBox1.Text = room.Name;

            guitars = room.GuitarAmps;
            foreach (Equipment amp in room.GuitarAmps)            
                guitarNum.Items.Add(amp.Name);
            guitarNum.SelectedIndex = Math.Min(0, guitarNum.Items.Count-1);

            basses = room.BassAmps;
            foreach (Equipment amp in room.BassAmps)
                bassNum.Items.Add(amp.Name);
            bassNum.SelectedIndex = Math.Min(0, bassNum.Items.Count-1);

            other = room.OtherMicrophones;
            foreach (Equipment item in room.OtherMicrophones)
                otherNum.Items.Add(item.Name);
            otherNum.SelectedIndex = Math.Min(0, otherNum.Items.Count-1);

            drumDescript.Text = room.Drums.Description;
            drumName.Text = room.Drums.Name;
            drumURL.Text = room.Drums.URL;

            EnumConverter ec = new EnumConverter(typeof(DrumParts));
            ec.ConvertToString(room.DrumParts);

            Array a = Enum.GetValues(typeof(DrumParts));
            for (int i = 0; i < a.Length; i++)
            {
              //  MessageBox.Show(a.GetValue(i).ToString());
            }
            //drumPartsList.Items.
        }
        public Room SaveRoom()
        {
            room = new Room();

            room.Drums.Name = drumName.Text;
            room.Drums.Description = drumDescript.Text;
            room.Drums.URL = drumURL.Text;
            //room.DrumParts TODO:

            room.BassAmps = basses;
            room.GuitarAmps = guitars;
            room.OtherMicrophones = other;

            room.Name = nametextbox.Text;

            return room;
        }


        private void guitarName_Changed(object sender, EventArgs e)
        {                   
            int id = guitarNum.SelectedIndex;
            guitars[id].Name = guitarName.Text;
            guitarNum.Items[id] = guitars[id].Name;
        }

     
        private void guitarNum_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = guitarNum.SelectedIndex;
            
            guitarName.Text = guitars[index].Name;
            guitarDescript.Text = guitars[index].Description;
            guitarURL.Text = guitars[index].URL;

            guitarDescript.Enabled = true;
            guitarName.Enabled = true;
            guitarURL.Enabled = true;
        }

        private void bassNum_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = bassNum.SelectedIndex;

            bassName.Text = basses[index].Name;
            bassDescript.Text = basses[index].Description;
            bassURL.Text = basses[index].URL;

            bassName.Enabled = true;
            bassDescript.Enabled = true;
            bassURL.Enabled = true;

        }

        private void otherNum_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = otherNum.SelectedIndex;

            otherName.Text = other[index].Name;
            otherDescript.Text = other[index].Description;
            otherURL.Text = other[index].URL;

            otherName.Enabled = true;
            otherDescript.Enabled = true;
            otherURL.Enabled = true;

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            Caption = nametextbox.Text;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            guitars.Add(new Equipment("New guitar amp","","http://"));
            guitarNum.Items.Add("New guitar amp");
            guitarNum.SelectedIndex = guitarNum.Items.Count - 1;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int id = guitarNum.SelectedIndex;
            
            if (id == -1)
                return;

            guitars.RemoveAt(id);
            guitarNum.Items.RemoveAt(id);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            basses.Add(new Equipment("New bass amp", "", "http://"));
            bassNum.Items.Add("New bass amp");
            bassNum.SelectedIndex = bassNum.Items.Count - 1;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            int id = bassNum.SelectedIndex;

            if (id == -1)
                return;

            basses.RemoveAt(id);
            bassNum.Items.RemoveAt(id);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            other.Add(new Equipment("New item", "", "http://"));
            otherNum.Items.Add("New item");
            otherNum.SelectedIndex = otherNum.Items.Count - 1;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            int id = otherNum.SelectedIndex;

            if (id == -1)
                return;

            other.RemoveAt(id);
            otherNum.Items.RemoveAt(id);
        }

        private void guitarURL_TextChanged(object sender, EventArgs e)
        {
            int id = guitarNum.SelectedIndex;

            guitars[id].URL = guitarURL.Text;
        }

        private void guitarDescript_TextChanged(object sender, EventArgs e)
        {
            int id = guitarNum.SelectedIndex;

            guitars[id].Description = guitarDescript.Text;
        }

        private void bassName_TextChanged(object sender, EventArgs e)
        {
            int id = bassNum.SelectedIndex;

            basses[id].Name = bassName.Text;
            bassNum.Items[id] = basses[id].Name;
        }

        private void bassURL_TextChanged(object sender, EventArgs e)
        {
            int id = bassNum.SelectedIndex;

            basses[id].URL = bassURL.Text;
        }

        private void bassDescript_TextChanged(object sender, EventArgs e)
        {
            int id = bassNum.SelectedIndex;

            basses[id].Description = bassDescript.Text;
        }


        private void otherName_TextChanged(object sender, EventArgs e)
        {
            int id = otherNum.SelectedIndex;

            other[id].Name = otherName.Text;
            otherNum.Items[id] = other[id].Name;
        }

        private void otherURL_TextChanged(object sender, EventArgs e)
        {
            int id = otherNum.SelectedIndex;

            other[id].URL = otherURL.Text; ;
        }

        private void otherDescript_TextChanged(object sender, EventArgs e)
        {
            int id = otherNum.SelectedIndex;

            other[id].Description = otherDescript.Text;
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }


 

        
    }
}
